package ru.ccfit.nsu.g7204.dronov.adPlatform;

import ru.ccfit.nsu.g7204.dronov.adPlatform.system.db.DBConnectionHolder;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Drongo
 * Date: 18.03.11
 * Time: 20:57
 * To change this template use File | Settings | File Templates.
 */
public class ClientsFormController implements ClientsFormListener {
    private ClientDBManager dbManager;
    private ImplementationType type;
    private DBConnectionHolder dbConnectionHolder;
    private int showingInterval;

    public void updateDbInfo(DBConnectionHolder dbConnectionHolder) {
        this.dbConnectionHolder = dbConnectionHolder;
        dbManager=new ClientDBManager(dbConnectionHolder);
    }

    public ClientsFormController(DBConnectionHolder dbConnectionHolder) {
        dbManager=new ClientDBManager(dbConnectionHolder);
        this.dbConnectionHolder = dbConnectionHolder;
        type= ImplementationType.One;
        showingInterval=-1;
    }

    public void delClient(String id) {
        dbManager.delClient(id);
    }

    public void delAll() {
        dbManager.delAll();
    }

    public void setShowingInterval(int showingInterval) {
        this.showingInterval=showingInterval;
        dbManager.setShowingInterval(showingInterval);
    }

    public int getShowingInterval() {
        if (showingInterval<0)
            showingInterval=dbManager.getShowingInterval();
        return showingInterval;
    }

    public List<String> getClients() {
        return dbManager.getClients();
    }

    public void setType(ImplementationType type) {
        this.type=type;

    }

    public void showDetails(String client) {
        new ClientDetailsForm(new ClientDetailsFormController(dbConnectionHolder, client, type));
    }
}
